<?php
namespace app\manage\controller;
use think\Db;

class DataChannelGame extends Base
{
    public function index(){
        if(request()->isAjax() || input('?export')){
            $page = input('page');
            $limit = input('limit');
            $plat = input('plat');
            $date = explodeTime(input('date'));
            $channelId = input('channel_id');
            $gameId = input('game_id');

            if( strtotime(date('Y-m-d', $date['end_time'])) == strtotime(date('Y-m-d', time())) ){
                $selectChannel = model('Data')->selectChannelGameNow($page, $limit, $plat, $date['start_time'], $date['end_time'], $channelId, $gameId);
            }else{
                $selectChannel = model('Data')->selectChannelGameOld($page, $limit, $plat, $date['start_time'], $date['end_time'], $channelId, $gameId);
            }
            if(input('?export')){
                array_unshift($selectChannel['data'], ['统计日期', '渠道ID', '渠道名称', '游戏ID', '游戏名称', '游戏新增', '游戏创角', '游戏活跃', '付费人数', '付费金额', '付费率', '新增用户ARPU', '活跃用户ARPU', '付费用户ARPU']);
                exportExcel($selectChannel['data'], input('date').'渠道游戏统计', input('date').'渠道游戏统计');
            }

            $this->layTable(0, '渠道游戏统计', $selectChannel['data'], $selectChannel['count'], $selectChannel['sum']);
        }else{
            $date = date('Y-m-d', time()-86400).' - '.date('Y-m-d', time()-86400);
            $today = date('Y-m-d', time()).' - '.date('Y-m-d', time());
            return view('', ['date'=>$date, 'today'=>$today]);
        }
    }
}